package starfield.modpack;

import java.awt.Color;
import java.io.File;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import org.apache.commons.validator.routines.UrlValidator;
import starfield.ValidationException;
import starfield.MetadataVersion;

public class ModpackDialog extends javax.swing.JDialog {

	private boolean hasAnswered;
	private Modpack modpack;
	
	private ModpackDialog(java.awt.Frame parent, boolean modal) {
		super(parent, modal);
        setLocationRelativeTo(parent);
		initComponents();
	}
	
	public static ModpackDialog show(java.awt.Frame parent, boolean modal) {
		ModpackDialog modpackDialog = new ModpackDialog(parent, modal);
		modpackDialog.setTitle("New modpack");
        modpackDialog.setVisible(true);
		return modpackDialog;
	}
	
	public static ModpackDialog show(java.awt.Frame parent, boolean modal, Modpack modpack) {
		ModpackDialog modpackDialog = new ModpackDialog(parent, modal);
		modpackDialog.setTitle("Edit modpack '" + modpack.getDisplayName() + "'");
		modpackDialog.fillFromModpack(modpack);
        modpackDialog.setVisible(true);
		return modpackDialog;
	}

	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        okButton = new javax.swing.JButton();
        markdownLabel = new javax.swing.JLabel();
        authorsPane = new javax.swing.JScrollPane();
        authorsList = new javax.swing.JList();
        titleLabel = new javax.swing.JLabel();
        versionNumbersField = new javax.swing.JFormattedTextField();
        starboundVersionLabel = new javax.swing.JLabel();
        urlField = new javax.swing.JTextField();
        authorsToolbar = new javax.swing.JToolBar();
        addAuthorButton = new javax.swing.JButton();
        editAuthorButton = new javax.swing.JButton();
        removeAuthorButton = new javax.swing.JButton();
        authorsLabel = new javax.swing.JLabel();
        descriptionPane = new javax.swing.JScrollPane();
        descriptionField = new javax.swing.JTextArea();
        descriptionLabel = new javax.swing.JLabel();
        starboundVersionField = new javax.swing.JTextField();
        versionLabel = new javax.swing.JLabel();
        titleField = new javax.swing.JTextField();
        cancelButton = new javax.swing.JToggleButton();
        versionStageList = new javax.swing.JComboBox();
        urlLabel = new javax.swing.JLabel();
        directoryField = new javax.swing.JTextField();
        directoryLabel = new javax.swing.JLabel();
        directoryStateLabel = new javax.swing.JLabel();
        directoryLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(400, 500));

        okButton.setText("OK");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        markdownLabel.setForeground(javax.swing.UIManager.getDefaults().getColor("textInactiveText"));
        markdownLabel.setText("(supports Markdown)");

        authorsList.setModel(new DefaultListModel());
        authorsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        authorsPane.setViewportView(authorsList);
        authorsList.getSelectionModel().addListSelectionListener(
            new javax.swing.event.ListSelectionListener() {
                @Override
                public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                    authorsListSelectionChanged(evt);
                }
            }
        );

        titleLabel.setText("Name:");

        versionNumbersField.setText("1.0");

        starboundVersionLabel.setText("Starbound version:");

        authorsToolbar.setFloatable(false);
        authorsToolbar.setRollover(true);
        authorsToolbar.setFocusable(false);

        addAuthorButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/starfield/icons/add.png"))); // NOI18N
        addAuthorButton.setText("Add");
        addAuthorButton.setFocusable(false);
        addAuthorButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        addAuthorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addAuthorButtonActionPerformed(evt);
            }
        });
        authorsToolbar.add(addAuthorButton);

        editAuthorButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/starfield/icons/pencil.png"))); // NOI18N
        editAuthorButton.setText("Edit");
        editAuthorButton.setEnabled(false);
        editAuthorButton.setFocusable(false);
        editAuthorButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        editAuthorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editAuthorButtonActionPerformed(evt);
            }
        });
        authorsToolbar.add(editAuthorButton);

        removeAuthorButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/starfield/icons/delete.png"))); // NOI18N
        removeAuthorButton.setText("Remove");
        removeAuthorButton.setEnabled(false);
        removeAuthorButton.setFocusable(false);
        removeAuthorButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        removeAuthorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeAuthorButtonActionPerformed(evt);
            }
        });
        authorsToolbar.add(removeAuthorButton);

        authorsLabel.setText("Author(s):");

        descriptionPane.setHorizontalScrollBar(null);

        descriptionField.setColumns(20);
        descriptionField.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
        descriptionField.setRows(5);
        descriptionField.setTabSize(4);
        descriptionField.setLineWrap(true);
        descriptionField.setWrapStyleWord(true);
        descriptionPane.setViewportView(descriptionField);

        descriptionLabel.setText("Description:");

        versionLabel.setText("Version:");

        titleField.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {
            public void changedUpdate(javax.swing.event.DocumentEvent evt) {
                titleFieldTextChanged(evt);
            }
            public void removeUpdate(javax.swing.event.DocumentEvent evt) {
                titleFieldTextChanged(evt);
            }
            public void insertUpdate(javax.swing.event.DocumentEvent evt) {
                titleFieldTextChanged(evt);
            }
        });

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        versionStageList.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Alpha", "Beta", "Stable", "Experimental" }));

        urlLabel.setText("URL:");

        directoryField.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {
            public void changedUpdate(javax.swing.event.DocumentEvent evt) {
                directoryFieldTextChanged(evt);
            }
            public void removeUpdate(javax.swing.event.DocumentEvent evt) {
                directoryFieldTextChanged(evt);
            }
            public void insertUpdate(javax.swing.event.DocumentEvent evt) {
                directoryFieldTextChanged(evt);
            }
        });

        directoryLabel.setLabelFor(directoryField);
        directoryLabel.setText("Directory:");

        directoryStateLabel.setText(" ");

        directoryLabel1.setForeground(javax.swing.UIManager.getDefaults().getColor("textInactiveText"));
        directoryLabel1.setLabelFor(directoryField);
        directoryLabel1.setText("modpacks/");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(starboundVersionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
                            .addComponent(versionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(starboundVersionField))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(okButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(directoryLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(authorsLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(descriptionLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(titleLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(markdownLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(urlLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(versionStageList, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(versionNumbersField, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(authorsToolbar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(authorsPane, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE)))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(descriptionPane)
                                    .addComponent(titleField)
                                    .addComponent(directoryStateLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(urlField, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addComponent(directoryLabel1)
                                        .addGap(2, 2, 2)
                                        .addComponent(directoryField)))))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(titleLabel)
                    .addComponent(titleField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(directoryField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(directoryLabel)
                    .addComponent(directoryLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(directoryStateLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(urlLabel)
                    .addComponent(urlField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(descriptionLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(markdownLabel)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(descriptionPane, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(authorsLabel)
                    .addComponent(authorsPane, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(authorsToolbar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(versionStageList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(versionLabel)
                    .addComponent(versionNumbersField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(starboundVersionLabel)
                    .addComponent(starboundVersionField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelButton)
                    .addComponent(okButton))
                .addContainerGap())
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
		try {
			validateModpack();
			hasAnswered = true;
			setVisible(false);
		} catch (ValidationException vex) {
			JOptionPane.showMessageDialog(this, vex.getMessage(), "Modpack validation", JOptionPane.ERROR_MESSAGE);
		}
    }//GEN-LAST:event_okButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
		hasAnswered = false;
		setVisible(false);
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void addAuthorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addAuthorButtonActionPerformed
		String newAuthor = JOptionPane.showInputDialog(
				this,
				"Enter the new author's name: ",
				null);
		
		if (newAuthor != null && !newAuthor.equals("")) {
			((DefaultListModel)authorsList.getModel()).addElement(newAuthor);
		}
    }//GEN-LAST:event_addAuthorButtonActionPerformed

    private void removeAuthorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeAuthorButtonActionPerformed
		if (authorsList.getSelectedIndex() != -1) {
			if (JOptionPane.showConfirmDialog(
				this,
				"Are you sure you want to remove the selected author?",
				"Remove author", 
				JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {

				((DefaultListModel)authorsList.getModel()).remove(authorsList.getSelectedIndex());
			}
		}
    }//GEN-LAST:event_removeAuthorButtonActionPerformed

    private void editAuthorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editAuthorButtonActionPerformed
		String author = JOptionPane.showInputDialog(
				this,
				"Enter the author's name: ",
				authorsList.getSelectedValue());
		
		if (author != null && !author.equals("")) {
			((DefaultListModel)authorsList.getModel()).setElementAt(author, authorsList.getSelectedIndex());
		}
    }//GEN-LAST:event_editAuthorButtonActionPerformed
    
	private void titleFieldTextChanged(javax.swing.event.DocumentEvent evt) {
		directoryField.setText(Modpack.inferDirectoryName(titleField.getText()));
	}
	
	private String getNewDirectoryName() {
		return directoryField.getText();
	}
	
	private String getOldDirectoryName() {
		return modpack != null ? modpack.getName() : null;
	}
	
	public boolean hasDirectoryNameChanged() {
		return !getNewDirectoryName().equals(getOldDirectoryName());
	}
	
	private void validateDirectoryName() throws ValidationException {
		String newDirectoryName = getNewDirectoryName();
		File newDirectory = new File(Modpack.getDirectoryPath(newDirectoryName));
		
		if (hasDirectoryNameChanged()) {
			if (newDirectoryName.length() == 0) {
				throw new ValidationException("The directory name cannot be empty.");
			}
			
			if (newDirectory.exists() && newDirectory.isDirectory()) {
				throw new ValidationException("The directory already exists.");
			}
			
			if (!Modpack.ensureDirectoryName(newDirectoryName)) {
				throw new ValidationException("The directory name contains invalid characters.");
			}
		}
	}
	
	private void directoryFieldTextChanged(javax.swing.event.DocumentEvent evt) {
		String error = null;

		try {
			validateDirectoryName();
		} catch (ValidationException vex) {
			error = vex.getMessage();
		}

		if (error == null) {
			directoryStateLabel.setIcon(new ImageIcon(getClass().getResource("/starfield/icons/tick.png")));
			directoryStateLabel.setForeground(Color.decode("#006400"));

			if (!hasDirectoryNameChanged()) {
				directoryStateLabel.setText("The directory has not changed.");
			} else {
				directoryStateLabel.setText("This is a valid directory!");
			}
		} else {
			directoryStateLabel.setIcon(new ImageIcon(getClass().getResource("/starfield/icons/cross.png")));
			directoryStateLabel.setForeground(Color.decode("#8B0000"));
			directoryStateLabel.setText(error);
		}
	}

	private void authorsListSelectionChanged(javax.swing.event.ListSelectionEvent evt) {
		boolean enabled = authorsList.getSelectedIndex() != -1;

		removeAuthorButton.setEnabled(enabled);
		editAuthorButton.setEnabled(enabled);
	}
	
	public void validateModpack() throws ValidationException {
		getModpackTitle();
		getDirectoryName();
		getSupportUrl();
		getDescription();
		getGameVersion();
		getVersion();
		getAuthors();
	}
	
	public void fillModpack(Modpack modpack) throws ValidationException {
		modpack.getMetadata().setTitle(getModpackTitle());
		modpack.getMetadata().setSupportUrl(getSupportUrl());
		modpack.getMetadata().setDescription(getDescription());
		modpack.getMetadata().setVersion(getVersion());
		modpack.getMetadata().setAuthors(getAuthors());
	}
	
	public void fillFromModpack(Modpack modpack) {
		this.modpack = modpack;
		
		setDirectoryName(modpack.getName());
		
		setModpackTitle(modpack.getMetadata().getTitle());
		setSupportUrl(modpack.getMetadata().getSupportUrl());
		setDescription(modpack.getMetadata().getDescription());
		setVersion(modpack.getMetadata().getVersion());
		setAuthors(modpack.getMetadata().getAuthors());
	}
	
	public boolean hasAnswered() {
		return hasAnswered;
	}
	
	public String getModpackTitle() {
		return titleField.getText();
	}
	
	public void setModpackTitle(String modpackTitle) {
		titleField.setText(modpackTitle);
	}
	
	public String getDirectoryName() throws ValidationException {
		validateDirectoryName();
		
		return directoryField.getText();
	}
	
	public void setDirectoryName(String directoryName) {
		directoryField.setText(directoryName);
	}
	
	public String getSupportUrl() throws ValidationException {
		String url = urlField.getText();
		
		if (url != null && !url.equals("") && !(new UrlValidator(new String[] { "http", "https" }).isValid(url))) {
			throw new ValidationException("Invalid URL.");
		}
		
		return url;
	}
	
	public void setSupportUrl(String url) {
		urlField.setText(url);
	}
	
	public String getDescription() {
		return descriptionField.getText();
	}
	
	public void setDescription(String description) {
		descriptionField.setText(description);
		descriptionField.setCaretPosition(0);
	}
	
	public String[] getAuthors() {
		String[] authors = new String[authorsList.getModel().getSize()];
		
		for (int i = 0; i < authors.length; i++) {
			authors[i] = authorsList.getModel().getElementAt(i).toString();
		}
		
		return authors;
	}
	
	public void setAuthors(String[] authors) {
		DefaultListModel listModel = new DefaultListModel();
		
		for (String author : authors) {
			listModel.addElement(author);
		}
		
		authorsList.setModel(listModel);
	}
	
	public MetadataVersion getVersion() throws ValidationException {
		String stage = versionStageList.getSelectedItem().toString();
		
		ArrayList<Integer> numbers = MetadataVersion.getNumbersFromString(versionNumbersField.getText());
		
		return new MetadataVersion(stage, numbers);
	}
	
	public void setVersion(MetadataVersion version) {
		versionStageList.getModel().setSelectedItem(version.getStage());
		versionNumbersField.setText(version.getNumbersString());
	}
	
	public String getGameVersion() {
		return starboundVersionField.getText();
	}
	
	public void setStarboundVersion(String starboundVersion) {
		starboundVersionField.setText(starboundVersion);
	}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addAuthorButton;
    private javax.swing.JLabel authorsLabel;
    private javax.swing.JList authorsList;
    private javax.swing.JScrollPane authorsPane;
    private javax.swing.JToolBar authorsToolbar;
    private javax.swing.JToggleButton cancelButton;
    private javax.swing.JTextArea descriptionField;
    private javax.swing.JLabel descriptionLabel;
    private javax.swing.JScrollPane descriptionPane;
    private javax.swing.JTextField directoryField;
    private javax.swing.JLabel directoryLabel;
    private javax.swing.JLabel directoryLabel1;
    private javax.swing.JLabel directoryStateLabel;
    private javax.swing.JButton editAuthorButton;
    private javax.swing.JLabel markdownLabel;
    private javax.swing.JButton okButton;
    private javax.swing.JButton removeAuthorButton;
    private javax.swing.JTextField starboundVersionField;
    private javax.swing.JLabel starboundVersionLabel;
    private javax.swing.JTextField titleField;
    private javax.swing.JLabel titleLabel;
    private javax.swing.JTextField urlField;
    private javax.swing.JLabel urlLabel;
    private javax.swing.JLabel versionLabel;
    private javax.swing.JFormattedTextField versionNumbersField;
    private javax.swing.JComboBox versionStageList;
    // End of variables declaration//GEN-END:variables
}
